/*************************************************************************
> File Name: 3.c
> Author: hzy
> Created Time: 2023-07-24 15:44:32
> Description: 3、计算一个字符串的空格数，并删除全部空格（指针）
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    char arr[] = "a ab ab a ";
    char *p = arr;

    int n = 0;

    while (*p != '\0')
    {
        if (*p == ' ')
        {
            n++;
            char *q = p;
            while (*q != '\0')
            {
                *q = *(q + 1);
                *q++;
            }
        }
        else
        {
            *p++;
        }
    }

    printf("该字符串中有%d个空格：\n", n);
    printf("修改后的字符串为:");
    p = arr;
    puts(p);

    printf("\n");

    return 0;
}